package cn.scw.project.system.controller;

import cn.scw.common.constant.SysConsts;
import cn.scw.framework.aspectj.lang.annotation.Log;
import cn.scw.framework.aspectj.lang.enums.BusinessType;
import cn.scw.framework.web.controller.BaseController;
import cn.scw.framework.web.domain.AjaxResult;
import cn.scw.framework.web.page.TableDataInfo;
import cn.scw.project.system.domain.netework.bean.SysDealerAddReq;
import cn.scw.project.system.domain.netework.bean.SysDealerListReq;
import cn.scw.project.system.domain.vo.SysDealerVo;
import cn.scw.project.system.service.ISysDealerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 经销商Controller
 *
 * @author api
 * @date 2020-05-20
 */
@Api(tags = "经销商")
@RestController
@RequestMapping(SysConsts.CONTEXT_PATH+"/system/dealer")
public class SysDealerController extends BaseController {
    @Autowired
    private ISysDealerService sysDealerService;

    @ApiOperation("查询经销商列表")
//    @PreAuthorize("@ss.hasPermi('system:dealer:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysDealerListReq req) {
        startPage();

        List<SysDealerVo> list = sysDealerService.selectSysDealerList(req);
        return getDataTable(list);
    }

    @ApiOperation("财务统计")
    @GetMapping("/count")
    public AjaxResult count() {
        return sysDealerService.count();
    }

    @ApiOperation("获取经销商详细信息")
//    @PreAuthorize("@ss.hasPermi('system:dealer:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(sysDealerService.selectSysDealerVoById(id));
    }

    @ApiOperation("新增经销商")
//    @PreAuthorize("@ss.hasPermi('system:dealer:add')")
    @Log(title = "经销商", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(SysDealerAddReq req) {

        return toAjax(sysDealerService.insertSysDealer(req)
        );
    }

    @ApiOperation("修改经销商")
//    @PreAuthorize("@ss.hasPermi('system:dealer:edit')")
    @Log(title = "经销商", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(SysDealerAddReq sysDealer) {
        return toAjax(sysDealerService.updateSysDealer(sysDealer));
    }

    @ApiOperation("删除经销商")
//    @PreAuthorize("@ss.hasPermi('system:dealer:remove')")
    @Log(title = "经销商", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sysDealerService.deleteSysDealerByIds(ids));
    }
}
